package com.buffer.springai.controller;

import com.buffer.springai.service.StreamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@RestController
@RequestMapping("/ai/stream")
public class SpringAIStreamController {

    @Autowired
    private StreamService streamService;

    @RequestMapping(value = "/ask", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter askAiStream(@RequestParam String content) {
        // 创建SseEmitter并设置超时时间
        SseEmitter emitter = new SseEmitter(Long.MAX_VALUE);
        streamService.askAIWithStream(content, emitter);
        return emitter;
    }
}